home *** CD-ROM | disk | FTP | other *** search
- Path: news.nacm.com!usenet
- From: brandon@criterion.com (Brandon Wallace)
- Newsgroups: comp.lang.c++,comp.lang.fortran
- Subject: Re: coupling c++ code with fortran
- Date: 3 Jan 1996 16:23:33 GMT
- Organization: Nicholas|Applegate Capital Management, San Diego, CA
- Message-ID: <4ceai5$2oa@news.nacm.com>
- References: <4ce0sp$ddv@fontainebleau.ensmp.fr>
- NNTP-Posting-Host: 204.255.80.4
- X-Newsreader: knews 0.9.2
- In-Reply-To: <4ce0sp$ddv@fontainebleau.ensmp.fr>
- To: salignac@cig.ensmp.fr
-
- In article <4ce0sp$ddv@fontainebleau.ensmp.fr>,
- salignac@cig.ensmp.fr writes:
- -> Hello !
- ->
- -> I'm trying to call a C++ subroutine in a Fortran 77 code.
- -> The compilation fails while linking: it seems impossible
- -> for the fortran compiler/linker to recognize the C++ function.
- -> In plain C, the problem is easily solved by adding underscores
- -> at the start of the C-function name, but this is clearly
- -> different for C++....
- ->
- -> Does anyone know which syntax is recognized by both compilers?
- -> Are there examples available ?
- ->
- -> I currently use the gnu-C++ compiler (v.2.7.0) and the standard
- -> Unix f77 compiler. Trials with the gnu-f77 compiler failed
- -> for the same reason.
- -> Answers by e-mail would be most appreciated.
-
- Declare your C++ function extern "C"...as
-
- extern "C" void callablefromfortran_ (void);
-
- Also, be aware that problems can occur if you use anything
- like the iostreams package. You will get things like
- bus-errors. You should really have a C++ main
- which includes <iostream.h>, and it should call your
- FORTRAN function, which then can go and call your C++
- function, etc...Then you should link with the g++, and
- make sure and include the fortran libraries (with the
- sparccompiler, they are -lF77 -lM77 -lm).
- --
- Brandon Wallace
- Nicholas | Applegate Capital Management
- mailto:bman@criterion.com http://www.criterion.com/home-pages/brandon
- "I live life face down in the fast lane."
-
-